DEFINE MISSIONS 1
DEFINE MISSION 0 AT @MISSN_09
DEFINE EXTERNAL_SCRIPTS 0

DEFINE UNKNOWN_EMPTY_SEGMENT 0

DEFINE UNKNOWN_THREADS_MEMORY 500

{$VERSION 3.1.0027}
var
 $PLAYER_CHAR: Player
end // var 
//Main thread starts here
03A4: name_thread 'MAIN' 
//Set the screen BLACK immediately
016A: fade 0 time 0            

01F0: set_max_wanted_level_to 6 
0111: toggle_wasted_busted_check 0 
00C0: set_current_time_hours_to 8 minutes_to 0 
0629: change_integer_stat 181 to 4              //All Cities Open
062A: change_float_stat 165 to 800.0            //Energy
062A: change_float_stat 23 to 150.0             //Muscle
062A: change_float_stat 21 to 200.0             //Fat
062A: change_float_stat 160 to 150.0            //Driving Skill
0629: change_integer_stat 68 to 10              //Respect
//Loads Tenpenny as #SPECIAL01 or 290
023C: load_special_actor 'TENPEN' as 1 

//Create Player at Station
03CB: set_rendering_origin_at 1550.68 -1675.49 14.51
$PLAYER_CHAR = Player.Create(#NULL, 1596.6378, -1523.8016, 13.5991)
 
Player.SetClothes($PLAYER_CHAR, "VEST", "VEST", Torso)
Player.SetClothes($PLAYER_CHAR, "JEANSDENIM", "JEANS", Legs)
Player.SetClothes($PLAYER_CHAR, "SNEAKERBINCBLK", "SNEAKER", Shoes)
Player.SetClothes($PLAYER_CHAR, "PLAYER_FACE", "HEAD", Head)  
Player.Build($PLAYER_CHAR)

//Changes the player to ped model 290 Tenpenny
09C7: change_player $PLAYER_CHAR model_to 290 
01F5: $PLAYER_ACTOR = create_player_actor $PLAYER_CHAR 
07AF: $PLAYER_GROUP = player $PLAYER_CHAR group 
Actor.Angle($PLAYER_ACTOR) = 90.0
01B6: set_weather 1 
0001: wait 0 ms 
01B4: toggle_player $PLAYER_CHAR can_move false //We shut down control for the cameras to work 
04BB: select_interior 0 
016C: restart_if_wasted_at 1550.68 -1675.49 14.51 angle 90.0 town_number 0 
016D: restart_if_busted_at 1550.68 -1675.49 14.51 angle 90.0 town_number 0 
// Note: your missions have to use the variable defined here
0180: set_on_mission_flag_to $ONMISSION  
16@ = 0

$DEFAULT_WAIT_TIME = 250
$ONMISSION = 0   


016A: fade 1 time 500
0001: wait 1000 ms 
Player.CanMove($PLAYER_CHAR) = True
Camera.Restore_WithJumpCut
Camera.SetBehindPlayer

01B7: release_weather
03E6: remove_text_box 
                                               
$CRASH_MARKER = Marker.CreateIconAndSphere(16, 1597.3431, -1515.3278, 13.5899)

//Main Loop
:MAIN_LOOP
0001: wait $DEFAULT_WAIT_TIME ms
00BF: $TIME_HOURS = current_time_hours, $TIME_MINS = current_time_minutes

if and
$ONMISSION == 0
00F0:   actor $PLAYER_ACTOR 0 near_point 1597.3431 -1515.3278 radius 3.0 3.0 stopped_on_foot 
jf @MAIN_LOOP

start_mission 0

0002: jump @MAIN_LOOP 
//-----------------------------------------------------------------------
:MISSN_09
thread 'MISSN_09'
$ONMISSION = 1
gosub @MISSN_09_100

00D6: if
0112:   wasted_or_busted
004D: jump_if_false @MISSN_09_105

0050: gosub @MISSN_09_800 //Mission Failed
 
:MISSN_09_105
0050: gosub @MISSN_09_900
004E: end_thread


:MISSN_09_100
Model.Load(#QUAD)
Model.Load(#BANDITO)
Model.Load(#BMYPIMP)
Model.Load(157)
Model.Load(158)
Model.Load(159)
Model.Load(160)
Model.Load(161)
Model.Load(162)
Model.Load(357)
023C: load_special_actor 'TRUTH' as 2 
038B: load_requested_models
054C: use_GXT_table 'JABM08' 

:MISSN_09_110
wait 0
if and
Model.Available(#QUAD)
Model.Available(#BANDITO)
Model.Available(#BMYPIMP)
Model.Available(157)    //#CWFYHB
Model.Available(158)    //#CWMOFR
jf @MISSN_09_110 

if and
Model.Available(159)    //#CWMOHB1
Model.Available(160)    //#CWMOHB2
Model.Available(161)    //#CWMYFR
Model.Available(162)    //#CWMYHB1
Model.Available(357)
023D:   special_actor 2 loaded 
jf @MISSN_09_110 

//Cut scene Dollar Bill and Tenpenny
//Conversation about the Truth
100@ = 0
41@ = Actor.Create(7, #BMYPIMP, 1580.9761, -1517.3043, 13.5531)
07CD: AS_actor 41@ walk_to 1595.2507 -1515.7296 13.5858 stop_with_angle 270.0 within_radius 1.0 
01B4: toggle_player $PLAYER_CHAR can_move false
Actor.Angle($PLAYER_ACTOR) = 88.5
02A3: enable_widescreen 1 
wait 1000
067E: put_camera_on_actor $PLAYER_ACTOR with_offset -7.0 3.0 1.0 point_to_actor 41@ 0.0 mode 2 

:MISSN_09_115               
wait 0
if
00FE:   actor 41@ sphere 0 in_sphere 1595.2507 -1515.7296 13.5858 radius 1.0 1.0 1.0 
jf @MISSN_09_115

03CF: load_wav 45241 as 1  
0949: link_wav 1 to_actor $PLAYER_ACTOR 
067C: put_camera_on_actor $PLAYER_ACTOR with_offset -2.0 1.5 0.7 rotation 0.0 0.0 0.0 0.0 2 
0967: actor $PLAYER_ACTOR move_mouth -1 ms
00BC: show_text_highpriority GXT 'SFT01' time 1500 flag 1  
gosub @MISSN_09_120 //Play the line
0968: actor $PLAYER_ACTOR stop_mouth
if 
100@ == 0
jf @MISSN_09_140
03CF: load_wav 45242 as 1
0949: link_wav 1 to_actor 41@
067C: put_camera_on_actor 41@ with_offset 2.0 1.5 0.7 rotation 0.0 0.0 0.0 0.0 2 
0967: actor 41@ move_mouth -1 ms
00BC: show_text_highpriority GXT 'SFT02' time 3000 flag 1  
gosub @MISSN_09_120 
0968: actor 41@ stop_mouth
if 
100@ == 0
jf @MISSN_09_140
03CF: load_wav 45243 as 1
0949: link_wav 1 to_actor 41@
067C: put_camera_on_actor 41@ with_offset 2.0 1.5 0.7 rotation 0.0 0.0 0.0 0.0 2 
0967: actor 41@ move_mouth -1 ms
00BC: show_text_highpriority GXT 'SFT03' time 3000 flag 1  
gosub @MISSN_09_120 
0968: actor 41@ stop_mouth
if 
100@ == 0
jf @MISSN_09_140
03CF: load_wav 45244 as 1
0949: link_wav 1 to_actor $PLAYER_ACTOR 
067C: put_camera_on_actor $PLAYER_ACTOR with_offset -2.0 1.5 0.7 rotation 0.0 0.0 0.0 0.0 2 
0967: actor $PLAYER_ACTOR move_mouth -1 ms
00BC: show_text_highpriority GXT 'SFT04' time 2500 flag 1  
gosub @MISSN_09_120 
0968: actor $PLAYER_ACTOR stop_mouth
if 
100@ == 0
jf @MISSN_09_140
03CF: load_wav 45247 as 1
0949: link_wav 1 to_actor 41@
067C: put_camera_on_actor 41@ with_offset 2.0 1.5 0.7 rotation 0.0 0.0 0.0 0.0 2 
0967: actor 41@ move_mouth -1 ms
00BC: show_text_highpriority GXT 'SFT05' time 8000 flag 1  
gosub @MISSN_09_120 
0968: actor 41@ stop_mouth
if 
100@ == 0
jf @MISSN_09_140
03CF: load_wav 45248 as 1
0949: link_wav 1 to_actor 41@
067C: put_camera_on_actor 41@ with_offset 2.0 1.5 0.7 rotation 0.0 0.0 0.0 0.0 2 
0967: actor 41@ move_mouth -1 ms
00BC: show_text_highpriority GXT 'SFT06' time 7000 flag 1  
gosub @MISSN_09_120 
0968: actor 41@ stop_mouth
if 
100@ == 0
jf @MISSN_09_140
03CF: load_wav 45246 as 1
0949: link_wav 1 to_actor $PLAYER_ACTOR 
067C: put_camera_on_actor $PLAYER_ACTOR with_offset 0.0 0.5 0.7 rotation 0.0 -45.0 0.0 0.0 2 
0967: actor $PLAYER_ACTOR move_mouth -1 ms
00BC: show_text_highpriority GXT 'SFT07' time 2000 flag 1  
gosub @MISSN_09_120 
0968: actor $PLAYER_ACTOR stop_mouth
if 
100@ == 0
jf @MISSN_09_140
03CF: load_wav 45249 as 1
0949: link_wav 1 to_actor 41@
067C: put_camera_on_actor 41@ with_offset 1.0 1.5 1.7 rotation 0.0 0.0 0.0 0.0 2 
0967: actor 41@ move_mouth -1 ms
00BC: show_text_highpriority GXT 'SFT08' time 8000 flag 1  
gosub @MISSN_09_120 
0968: actor 41@ stop_mouth
if 
100@ == 0
jf @MISSN_09_140
03CF: load_wav 45250 as 1
0949: link_wav 1 to_actor 41@
067C: put_camera_on_actor 41@ with_offset 2.0 2.5 1.7 rotation 0.0 0.0 0.0 0.0 2 
0967: actor 41@ move_mouth -1 ms
00BC: show_text_highpriority GXT 'SFT09' time 8000 flag 1  
gosub @MISSN_09_120 
0968: actor 41@ stop_mouth
//end_scene_skip 
jump @MISSN_09_140

:MISSN_09_120
wait 0
if
03D0:   wav 1 loaded 
jf @MISSN_09_120
03D1: play_wav 1 

:MISSN_09_130
wait 0
if or
00E1:   player 0 pressed_key 15 
00E1:   player 0 pressed_key 16 
00E1:   player 0 pressed_key 17 
then
100@ = 1
040D: unload_wav 1
return
end
if 
03D2:   wav 1 ended 
jf @MISSN_09_130

040D: unload_wav 1
return  
 
:MISSN_09_140
02A3: enable_widescreen 0 
03E5: show_text_box 'SFT10'
01B4: toggle_player $PLAYER_CHAR can_move true
Camera.Restore_WithJumpCut
Camera.SetBehindPlayer
018A: 40@ = create_checkpoint_at 17.3053 -2646.5452 40.4639
10@ = Car.Create(#QUAD, 32.7485, -2661.6067, 40.5449)
Car.Angle(10@) = 82.0
11@ = Car.Create(#BANDITO, 26.7485, -2637.25, 40.4185)
Car.Angle(10@) = 97.0
70@ = Car.Create(#BANDITO, -393.5951, -2640.0105, 144.2136)

:MISSN_09_150
wait 0
if
00FE:   actor $PLAYER_ACTOR sphere 1 in_sphere 17.3053 -2646.5452 40.4639 radius 1.0 1.0 1.0 
jf @MISSN_09_150
03E5: show_text_box 'SFT11'
060A: create_decision_maker_type 2 store_to 98@
01EB: set_traffic_density_multiplier_to 0.2 
0164: disable_marker 40@
32@ = 0                 //Timer
100@ = 0                //Marker Index
{This should help you understand how an array works better. All the checkpoints are
loaded into these variable sets to then be used.}
//Marker X Coords
101@ = -614.3694  
102@ = -393.5951  
103@ = -790.4372  
104@ = -1213.4271 
105@ = -1300.8    
106@ = -1161.4893 
107@ = -1005.3307 
108@ = -962.0974  
109@ = -831.3726  
110@ = -685.3581  
111@ = -443.2529  
//Marker Y Coords
112@ = -2413.2014
113@ = -2617.0105
114@ = -2694.6877
115@ = -2637.467 
116@ = -2392.9521
117@ = -2358.8281
118@ = -2420.0625
119@ = -2186.5151
120@ = -2025.8423
121@ = -1855.5834
122@ = -2023.8491
//Marker Z coords
123@ =  28.9264 
124@ =  144.2136  
125@ =  85.3182 
126@ =   9.7209 
127@ =  23.9784 
128@ =  21.7954 
129@ =  69.5961 
130@ =  40.9331 
131@ =  22.6301 
132@ =  13.9836 
133@ =  44.8267 
//Create the checkpoints
:MISSN_09_180
wait 0
{Notice 101@ is the first variable in our array above? Look at the line below, 100@ is the index offset.
and the 11f just tells it to expect 11 floating point variables in the whole array 11i is integer.
Another way to look at this 43@(100@,11i) we are not increasing the values inside the varible but the
name of the varible 43@(1,11i) = 44@ and 43@(10,11i) = 53@ so this loop assigns values to 43@ to 53@. }
018A: 43@(100@,11i) = create_checkpoint_at 101@(100@,11f) 112@(100@,11f) 123@(100@,11f)
100@ += 1
if
100@ >= 11
jf @MISSN_09_180
//Pick the one the Truth is hanging out.
0209: 99@ = random_int_in_ranges 0 10 
42@ = Actor.Create(24, #SPECIAL02, 101@(99@,11f), 112@(99@,11f), 123@(99@,11f))
100@ = 0
:MISSN_09_190
wait 0
if 
803B:   not  99@ == 100@ // (int) 
jf @MISSN_09_195 
//Create a random hillbilly moonshiner 157 to 162
0209: 40@ = random_int_in_ranges 157 163 
41@ = Actor.Create(16, 40@, 101@(100@,11f), 112@(100@,11f), 123@(100@,11f))
01B2: give_actor 41@ weapon 33 ammo 999 
060B: set_actor 41@ decision_maker_to 98@
Actor.WeaponAccuracy(41@) = 50 
//This section defines the hillbilly's actions
0615: define_AS_pack_begin 1@ 
0605: actor -1 perform_animation_sequence "SWT_WLLPK_L" IFP_file "SWAT" 8.0 loop 0 0 0 0 time -1 // versionA 
0605: actor -1 perform_animation_sequence "SWT_WLLSHOOT_IN_L" IFP_file "SWAT" 8.0 loop 0 1 1 0 time -1 // versionA 
0638: AS_actor -1 stay_put 1 
07A5: AS_actor -1 attack_actor $PLAYER_ACTOR 1500 ms 
0638: AS_actor -1 stay_put 0 
0605: actor -1 perform_animation_sequence "SWT_WLLSHOOT_OUT_L" IFP_file "SWAT" 8.0 loop 0 1 1 0 time -1 // versionA 
0605: actor -1 perform_animation_sequence "SWT_WLLPK_L_BACK" IFP_file "SWAT" 8.0 loop 0 0 0 0 time -1 // versionA 
0643: set_AS_pack 1@ loop 1 
0616: define_AS_pack_end 1@ 
0618: assign_actor 41@ to_AS_pack 1@ 
061B: remove_references_to_AS_pack 1@

:MISSN_09_195
100@ += 1
if
100@ >= 11
jf @MISSN_09_190

//Loop through all points
:MISSN_09_200
wait 0
100@ += 1
if
100@ >= 11
then
100@ = 0
end
//Disable Markers as you near them within 15 meters.
if
00FE:   actor $PLAYER_ACTOR sphere 0 in_sphere 101@(100@,11f) 112@(100@,11f) 123@(100@,11f) radius 15.0 15.0 15.0 
jf @MISSN_09_210
0164: disable_marker 43@(100@,11i)

//Found the Truth
:MISSN_09_210
if
00F3:   actor $PLAYER_ACTOR near_actor 42@ radius 15.0 15.0 0 on_foot
jf @MISSN_09_200
03E5: show_text_box 'SFT12'
//Kill all the Markers
100@ = 0
:MISSN_09_220
wait 0
0164: disable_marker 43@(100@,11i)
100@ += 1
if
100@ >= 11
jf @MISSN_09_220

:MISSN_09_250
43@ = Marker.CreateAboveActor(42@)

:MISSN_09_285
wait 0
0751: AS_actor 42@ flee_from_actor $PLAYER_ACTOR run_distance 100000.0 time 999999 unknown 1 3000 5000 away_radius 50.0 

//IF the Truth dies you fail mission
if  
not Actor.Dead(42@)
jf @MISSN_09_800
if
04AD:   actor 42@ in_water 
then
0321: kill_actor 42@  
end
if and
0611:   actor 42@ performing_animation "GETUP_FRONT" 
00F3:   actor $PLAYER_ACTOR near_actor 42@ radius 3.0 3.0 0 on_foot 
then
03E5: show_text_box 'SFT13'
wait 3000
fade 0 1000
:MISSN_09_300
wait 0
if
not fading
jf @MISSN_09_300
00BE: text_clear_all 
jump @MISSN_09_700  //Caught the Truth 
end

if
Actor.Dead($PLAYER_ACTOR)
jf @MISSN_09_285

return

:MISSN_09_700
054C: use_GXT_table 'TRU1' 
wait 0 
select_interior 12 
02E4: load_cutscene_data 'TRUTH_1' 

:MISSN_09_710
if 
86B9:   not cutscene_data_loaded 
else_jump @MISSN_09_720 
wait 0 
jump @MISSN_09_710 

:MISSN_09_720
02E7: start_cutscene 
fade 1 1000 

:MISSN_09_730
02E8: $129 = cutscenetime 
//The entire cut scene wasn't needed so we shut down after 90 seconds.
if
$129 < 90000
jf @MISSN_09_740

if 
82E9:   not cutscene_reached_end 
jf @MISSN_09_740 
wait 0 
jump @MISSN_09_730 

:MISSN_09_740

fade 0 1500
:MISSN_09_750
wait 0
if
not fading
jf @MISSN_09_750
02EA: end_cutscene
select_interior 0 
0169: set_fade_color_RGB 0 0 0 
Camera.Restore_WithJumpCut
Player.CanMove($PLAYER_CHAR) = True
02A3: enable_widescreen 0 
Actor.PutAt($PLAYER_ACTOR, -2195.9, -2258.029, 30.0)
Actor.Angle($PLAYER_ACTOR) = 141.0
0A0B: set_rendering_origin_at_3D_coord -2196.46 -2256.96 31.43 angle 141.0 
fade 1 500 
:MISSN_09_760
wait 0
if
not fading
jf @MISSN_09_760
030C: progress_made += 1 
0394: play_music 1 
Player.ClearWantedLevel($PLAYER_CHAR)
01E3: show_text_1number_styled GXT 'M_PASS' number 14000 time 5000 style 1  
Player.Money($PLAYER_CHAR) += 14000
return

:MISSN_09_800
$CRASH_MARKER = Marker.CreateIconAndSphere(16, 1597.3431, -1515.3278, 13.5899)
00BA: show_text_styled GXT 'M_FAIL' time 5000 style 1  // ~r~MISSION FAILED!
return

:MISSN_09_900
034F: destroy_actor_with_fade 41@
034F: destroy_actor_with_fade 42@
0164: disable_marker 40@
0164: disable_marker 43@
$ONMISSION = 0
mission_cleanup
return
